import request from "@/utils/request.ts";
import type {permissionAllResponseInter, roleAllInter, roleResponseInter} from "@/api/acl/role/type.ts";
import type {ResponseInter} from "@/api/commonInterFace.ts";

enum Api {
    role_url_all = "/admin/acl/role",
    role_url_add = "/admin/acl/role/save",
    role_url_update = "/admin/acl/role/update",
    role_url_all_permission = "/admin/acl/permission/toAssign",
    //分配权限
    role_url_set_permission = "/admin/acl/permission/doAssign",
    role_url_delete = "/admin/acl/role/remove",
}

export const reqAllRoleList = (page: number, limit: number, roleName: string) => request.get<string, roleResponseInter>(`${Api.role_url_all}/${page}/${limit}?username=${roleName}`)

export const reqRoleAddOrUpdate = (data: roleAllInter) => {
    if (data.id) {
        return request.put<string, ResponseInter>(Api.role_url_update, data)
    } else {
        return request.post<string, ResponseInter>(Api.role_url_add, data)
    }
}

// 获取所有权限
export const reqAllPermission = (id: number) => request.get<string, permissionAllResponseInter>(`${Api.role_url_all_permission}/${id}`)
// 分配权限
export const reqSetPermission = (roleId: number, permissionId: number[]) => request.post<string, ResponseInter>(`${Api.role_url_set_permission}?roleId=${roleId}&permissionId=${permissionId}`)
export const reqDeleteRole = (id: number) => request.delete<string, ResponseInter>(`${Api.role_url_delete}/${id}`)
